<template>
  <div>
    <!-- table -->
    <BreakSpace label="归档信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel3" :list="formList2" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formBackChangeHandle" />
    <BaseDialog :visible.sync="visibleEdit" :title="'质量改善跟踪编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <editDetail @close="editclose" @save="editsave" :rowData="rowDataSon"></editDetail>
    </BaseDialog>
    <BreakSpace label="故障码列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table3"
      :columns="columns3"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    >
    </FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="主损配件列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table4"
      :columns="columns4"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    >
    </FilterTable>
    <BreakSpace label="质量部回复信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel4" :list="formList3" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formAuditChangeHandle" />

    <BreakSpace label="质量报告列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table5"
      :columns="columns5"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns5 = columns5)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }">
      <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
    </div>
    <div style="margin-bottom: 4rem;"></div>
  </div>
</template>
<script>
  import { getPartType } from '@/api/dictionary/index';
  import { isFormEmpty } from '@/utils/index';
  import {quyRpQaCase} from '@/api/claim/factory/QualityInformationManagement_OEM/QualityInformationStatusMaintain';
  import {getListByPage} from '@/api/claim/factory/QualityInformationManagement_OEM/QualityInformationExamine';
  import editDetail from './editDetail.vue';
  export default {
    props: ['type', 'rowData'],
    // mixins: [dictionary],
    components: {
      editDetail
    },
    data() {
      return {
        collapse: false,
        infoId: null,
        columns3:this.creatHeader3(),
        columns4:this.creatHeader4(),
        columns5:this.creatHeader5(),
        // columns3: this.creatHeader3(),
        // topFilterInit: this.topFilterInitFun(),
        // fetchApi: getUser,
        fetchParams: {}, //ipa 接口
        selectedRows: [], //选中经销商
        formList2: this.backFormList(),
        formList3: this.aduitFormList(),
        saveData: null,
        saveData1:null,
        saveData2:null,
        saveData3:null,
        activeName: '审核记录',
        caseNoFlag:false,
        rowDataSon:{},
        visibleEdit: false,
      };
    },
    async created() {
      await this.getList(this.rowData.caseId);
      await this.chuqi();
    },
    methods: {
      async chuqi() {
        console.log("进来了")
        const res3 = await getPartType({type: 5563});
        if (res3.resultCode == 200) {
          this.formList2.find(x => x.fieldName == 'caseLevel').itemList = res3.data.map(y => ({
            text: y.codeCnDesc,
            value: y.codeId
          }));
        }
      },
      async getList(id) {
        let res = await quyRpQaCase({ id: id });
        let data = res.data;
        //为2个form赋值
        this.formList2.forEach(x => {
          x.initialValue = data[x.fieldName];
          if (x.fieldName == 'file1List') {
            x.initialValue = data.file1List.map((f) => ({ name: f.title, url: f.fileUrl }));
          }
        });
        for (let i in data) {
          this.formList3.map(y => {
            if (i == y.fieldName) {
              y.initialValue = data[i];
            }
          });
        }
        //为table赋值

        if (200 == res.resultCode) {
          let data = res.data;
          if (isFormEmpty(data)) {
            data = {};
          }

          let records4 = data.faultList;
          if (isFormEmpty(records4)) {
            records4 = [];
          }
          this.$refs.table3.$refs.pageTable.EXECUTE_INSERT(records4);

          let records5 = data.partList;
          if (isFormEmpty(records5)) {
            records5 = [];
          }
          this.$refs.table4.$refs.pageTable.EXECUTE_INSERT(records5);
          console.info(res);
          const res2 = await getListByPage({caseNo: data.caseNo,current: 1,
            currentPage: 1,
            limit: 100,
            pageNum: 1,
            pageSize: 100,
            size: 100});

          this.$refs.table5.$refs.pageTable.EXECUTE_INSERT(res2.data.records);

        }
      },
      editclose() {
        this.visibleEdit = false;
      },editsave() {
        this.visibleEdit = false;
      },
      faultAdd() {
        this.fault = true;
      },
      faultSave(val) {
        this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(val);
        this.fault = false;
      },
      faultClose() {
        this.fault = false;
      },
      //配件换下件列表
      peijianhuanxiajianadd() {
        this.peijianhuanxiajianlistaddflag = true;
      },
      //配件换下件
      peijianhuanxiajianClose() {
        this.peijianhuanxiajianlistaddflag = false;
      },
      peijianhuanxiajianSave(val) {
        this.$refs.table2.$refs.pageTable.EXECUTE_DELETE(this.$refs.table2.$refs.pageTable.list);
        this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(val);
        this.peijianhuanxiajianlistaddflag = false;
      },
      delsFunXj(data) {
        this.$refs.table1.$refs.pageTable.EXECUTE_DELETE([data]);
      },
      selectApplicationCode(){
        this.application = true;
      },
      selectpartCode() {
        this.zhusunjian = true;
      },
      selectRono() {
        this.weixiugongdan = true;
      },
      selectfaultCode() {
        this.guzhangxianxiangdaima = true;
      },
      selectcaseNo() {
        this.caseNoFlag = true;
      },
      formChangeHandle(val) {
        console.log(val);
        this.saveData = val;
      },
      formQuaChangeHandle(val) {
        console.log(val);
        this.saveData1 = val;
      },
      formBackChangeHandle(val) {
        this.saveData2 = val;
      },
      formAuditChangeHandle(val) {
        console.log(val);
        this.saveData3 = val;
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = val;
        console.log(val);
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },
      //取消操作
      closeDialog() {
        this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
      },
      //维修工单
      weixiugongdanClose() {
        this.weixiugongdan = false;
      },
      guzhangxianxiangdaimanClose() {
        this.guzhangxianxiangdaima = false;
      },
      applicationClose(){
        this.application = false;
      },

      //主损件
      zhusunjianClose() {
        this.zhusunjian = false;
      },

      //配件换下件
      caseNoClose() {
        this.caseNoFlag = false;
      },
      detail(val) {
        this.rowDataSon = val;
        this.visibleEdit = true;
      },

      backFormList() {
        return [
          {
            type: 'INPUT',
            label: '案例编号',
            fieldName: 'caseNo',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '案例主题',
            fieldName: 'caseTitle',
            selfCols: 2,// 元素占据几行
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '车型名称',
            fieldName: 'modelName',
            placeholder: '请输入数量...',
            disabled: true // 置会
          },
          {
            type: 'SELECT',
            label: '故障等级',
            fieldName: 'caseLevel',
            placeholder: '请选择...',
            itemList: [],
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '案例创建日期',
            fieldName: 'createdAt',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '故障现象代码',
            fieldName: 'faultCode',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '故障现象描述',
            fieldName: 'faultName',
            readonly: true,// 只读
            disabled: true, // 置会
          },
          {
            type: 'INPUT',
            label: '故障次数',
            fieldName: 'faultTimes',
            readonly: true,// 只读
            disabled: true, // 置会
            initialValue:0,
          },
          {
            type: 'INPUT',
            label: '一级代码',
            fieldName: 'sysCode1',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '一级名称',
            fieldName: 'sysName1',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '二级代码',
            fieldName: 'sysCode2',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '二级名称',
            fieldName: 'sysName2',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '三级代码',
            fieldName: 'sysCode3',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '三级名称',
            fieldName: 'sysName3',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '故障代码',
            fieldName: 'sysCode4',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'INPUT',
            label: '故障名称',
            fieldName: 'sysName4',
            placeholder: '请输入数量...',
            readonly: true,// 只读
            disabled: true // 置会
          },
          {
            type: 'TEXT_AREA',
            label: '案例描述',
            fieldName: 'caseInfo',
            selfCols: 3,// 元素占据几行
            rows: 2,
            disabled: true // 置会
          },
          {
            type: 'TEXT_AREA',
            label: '建议',
            fieldName: 'addviseInfo',
            selfCols: 3,// 元素占据几行
            rows: 3,
            disabled: true // 置会
          },
          {
            type: 'UPLOAD_FILE',
            label: '上传文件',
            fieldName: 'file1List',
            placeholder: '上传文件...',
            initialValue: [],
            disabled: true,
            upload: {
              actionUrl: '/api/file/oss/upload',
              limit: 2,
              // tipText: '只能上传pdf格式'
            }
          }
        ];
      },
      // //历史审核记录
      // creatHeader3() {
      //   return [
      //     {
      //       title: '序号',
      //       dataIndex: 'index',
      //       width: 80,
      //       sorter: true,
      //       render: props => {
      //         return <span>{props.row.index + 1}</span>;
      //       }
      //     },
      //     {title: '操作人', dataIndex: 'checkBy', sorter: true},
      //     {title: '操作时间', dataIndex: 'checkAt', sorter: true},
      //     {title: '操作类型', dataIndex: 'checkStatus', sorter: true},
      //     {title: '操作备注', dataIndex: 'checkRemarks', sorter: true}
      //   ];
      // },
      //故障码列表
      creatHeader3(){
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {title: '故障码', dataIndex: 'faultCode', sorter: true},
          {title: '故障码描述', dataIndex: 'faultName', sorter: true},
          {title: '出现次数', dataIndex: 'num', sorter: true},
        ];
      },
      //配件列表
      creatHeader4() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '配件代码', dataIndex: 'partCode', sorter: true },
          { title: '配件名称', dataIndex: 'partName', sorter: true },
        ];
      },
      aduitFormList(){
        return [
          {
            type: 'INPUT',
            label: '调查结论',
            fieldName: 'inConclusion',
          },
          {
            type: 'INPUT',
            label: '更新日期',
            fieldName: 'projectDate',
          },
          {
            type: 'INPUT',
            label: '故障等级',
            fieldName: 'resultLevel',
          },
        ]
      },
      creatHeader5() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '操作',
            dataIndex: 'column-action',
            width: 100,
            fixed: 'left',
            render: props => {
              return (
                <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.detail(props.row)}>
              明细
              </multiuse-button>
              </div>
            );
            }
          },
          { title: '质量报告状态', dataIndex: 'statusStr', sorter: true },
          { title: '质量报告单号', dataIndex: 'reportNo', sorter: true },
          { title: '索赔单号', dataIndex: 'cmsClaimNo', sorter: true },
          { title: '维修工单号', dataIndex: 'roNo', sorter: true },
          { title: 'VIN', dataIndex: 'vin', sorter: true },
          { title: '生产日期', dataIndex: 'prodDate', sorter: true,dateFormat: 'yyyy-MM-dd' },
          { title: '销售日期', dataIndex: 'saleDate', sorter: true,dateFormat: 'yyyy-MM-dd' },
          { title: '车型名称', dataIndex: 'modelName', sorter: true },
          { title: '主损件代码', dataIndex: 'partCode', sorter: true },
          { title: '主损件名称', dataIndex: 'partName', sorter: true },
          { title: '行驶里程', dataIndex: 'driveMile', sorter: true },
          { title: '故障现象代码', dataIndex: 'faultCode', sorter: true },
          { title: '故障现象名称', dataIndex: 'faultName', sorter: true },
          { title: '故障原因代码', dataIndex: 'sysCode4', sorter: true },
          { title: '故障原因名称', dataIndex: 'sysName4', sorter: true },
          { title: '维修开始时间', dataIndex: 'serviceBeginDate', sorter: true },
          { title: '维修结束时间', dataIndex: 'serviceEndDate', sorter: true },
          { title: '案例主题', dataIndex: '', sorter: true },
          { title: '申请时间', dataIndex: 'applyAt', sorter: true },
          { title: '申请人', dataIndex: 'applyBy', sorter: true },
          { title: '审核时间', dataIndex: 'checkAt', sorter: true },
          { title: '审核人', dataIndex: 'checkBy', sorter: true }
        ];
      },
    }
  };
</script>

<style lang="less" scoped></style>
